package vip.xiaonuo.modular.file.config;

import cn.hutool.core.io.FileUtil;
import cn.hutool.system.SystemUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * LocalFileConfig
 *
 * @author JackLee
 */
@Configuration
@ConfigurationProperties(prefix = "ninemm.file")
@Data
public class LocalFileConfig {

    /**
     * 文件存储位置
     */
    private String path;


    public String getFileRootPath() {
        String rootPath = path;

        if (!FileUtil.exist(rootPath)) {
            FileUtil.mkdir(rootPath);
        }

        StringBuilder builder = new StringBuilder(rootPath);
        if (!rootPath.endsWith(File.separator))
            builder.append(File.separator);
        return builder.toString();
    }
}
